home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / lu62 / getsess.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  10KB  |  341 lines

  1. /*********************************************************
  2. *                                                        *
  3. *                  Get Session                           *
  4. *                                                        *
  5. *   This procedure handles the allocation of half-       *
  6. *   session which will be used for conversation.         *
  7. *                                                        *
  8. *   INPUT :  GET_SESSION record.                         *
  9. *   OUTPUT:  SESSION_ALLOCATED record.                   *
  10. *                                                        *
  11.  *                                                       *
  12.  * CopyRight 1995. Nicholas Poljakov all rights reserved.*
  13.  *                                                       *
  14. *********************************************************/
  15. #include <state1.h>
  16. #include <stdio.h>
  17. #include <session.h>
  18. #include <lucb.h>
  19. #include <tcb.h>
  20. #include <rcb.h>
  21. #include <scb.h>
  22. #include <rpl.h>
  23. #include <nib.h>
  24. #include <common.h>
  25. #include <malloc.h>
  26. #include <repass.h>
  27. #include <string.h>
  28. #include <drcb.h>
  29. #if OS_TYPE == 1
  30. #include <memory.h>
  31. #endif
  32. int sk_r_wt(void *);
  33. int SendBlock(void *, void *);
  34. int setrc(void *, void *);
  35. int sendhsf(void *);
  36. int sendhs(void *);
  37. int sendbm(void *, void *);
  38. int sendat(void *);
  39. int rtsend(void *);
  40. unsigned long rmfmh5(void *, void *);
  41. int recwait(void *);
  42. int rcvru(void *, void *);
  43. int rcvhs(void *, void *, void *, void *);
  44. int ralloc(void *, void *);
  45. int psrm(int, void *, void *);
  46. int ps_conv(int, void *);
  47. int proterr(void *, unsigned long);
  48. int preptrcv(void *, void *);
  49. int post_rcb(void *);
  50. struct repass *postopen(void *);
  51. int phsrec(void *);
  52. int pfmh5(void *);
  53. int opndst(void *);
  54. int obtsess(void *, unsigned char);
  55. int Lrf_handler(void *);
  56. int get_attr(void *);
  57. int fsm_error(unsigned char, void *);
  58. int fsm_conv(unsigned char, unsigned char, void *);
  59. int flush (void *);
  60. int dcp(void *);
  61. int dealloc(void *);
  62. int crtp(void *);
  63. int conv(void *);
  64. int chkparm(void *, void *);
  65. int check_end(unsigned int, void *);
  66. struct rqb *call_appl(void *);
  67. int buffmng(unsigned char, void *, void *, void *, unsigned, unsigned char, unsigned);
  68. unsigned long attltck(void *);
  69. unsigned long attacheck(void *);
  70. char *cgetmem(int, int);
  71. int sendhsf(void *);
  72. int opndst(void *);
  73. int alloc_rcb(void *, void *);
  74. int allocate(void *);
  75. int clsdst(void *);
  76.  
  77. get_sess(in, out)
  78. char *in;
  79. char *out;
  80. {
  81.     struct gets *p_gets;
  82.     struct sessa *p_sessa;
  83.     struct tcb *p_tcb;
  84.     struct rcb *p_rcb;
  85.     struct lucb *p_lucb;
  86.     struct scb *p_scb;
  87.     struct scb *temp;
  88.     struct scb *temp1;
  89.     struct rpl *p_rpl;
  90.     struct nib *p_nib;
  91.     struct repass *p_rep;
  92.     struct com *p_com;
  93.     struct drcb d_rcb;
  94.     char *pr;
  95.     unsigned long crl;
  96.     char *p;
  97.     int i;
  98.  
  99. #if OS_TYPE == 1
  100. /*********  Trace facility **********/
  101. unsigned int rtype;   /* type of record */
  102. unsigned int pnum;    /* point number */
  103. char pname[8];        /* name of module */
  104. char *drec;       /* record for dump */
  105. int  lenr;            /* record length */
  106.  
  107. rtype = INPROC;
  108. strcpy(pname, "getsess");
  109. pnum = 1;
  110. drec = NULL;
  111. lenr = 0;
  112. gtf(rtype, pname, pnum, drec, lenr);
  113. /***********************************/
  114. #endif
  115.  
  116.     p_gets = (struct gets *)in;
  117.     p_sessa = (struct sessa *)out;
  118.     p_tcb = p_gets -> p_tcb;
  119.     p_rcb = p_gets -> p_rcb;
  120.     p_lucb = p_tcb -> p_lucb;
  121.  
  122. /*
  123.  * Serching for the SCB for the LU_NAME specified in the RCB associating with
  124.  * this request.
  125.  */
  126.     temp = p_lucb -> scb_list;
  127.     temp1 = temp;
  128.     if (temp == NULL) {
  129.         goto All_scb;
  130.     }
  131.     while (temp != NULL) {
  132.         if (memcmp(temp -> lu_name, p_rcb -> lu_name, 8) != 0) {
  133.             goto Next_scb;
  134.         }
  135.         break;
  136.         Next_scb: temp1 = temp;
  137.                   temp = temp -> next;
  138.     }
  139.     if (temp == NULL) {
  140.         goto All_scb;
  141.     }
  142.     switch (temp -> use) {
  143.         case IN_USE :
  144.                       {
  145.                         p_sessa -> rc = UNSUC_RETRY;
  146.                         p_sessa -> p_scb = NULL;
  147.             d_rcb.p_rcb = p_rcb;
  148.             d_rcb.p_tcb = p_tcb;
  149.                         psrm(DEALLOCATE_RCB, &d_rcb, 0);
  150.             return 0;
  151.                       }
  152.         case FREE :
  153.                       {
  154.                         p_sessa -> rc = OK;
  155.                         p_sessa -> p_scb = temp;
  156.                         p_rcb -> p_scb = temp;
  157.                         temp -> use = IN_USE;
  158.                         temp -> p_rcb = p_rcb;
  159.                         p_com = p_rcb -> verb_ptr;
  160.                         p_rpl = temp -> p_rpl;
  161.                         p_rcb -> sess_corl = p_rpl -> arg;
  162.                         /*
  163.                         if ((i = sendhs(p_rcb)) == OK) {
  164.                             p_com -> prim_rc = OK;
  165.                         }
  166.                         else
  167.                                 p_com -> prim_rc = ALLOCATION_FAILURE_RETRY;
  168.                         */
  169.                         p_com -> prim_rc = OK;
  170.             return 0;
  171.                       }
  172.      }
  173.      All_scb:
  174.              if (p_lucb -> cur_sess < p_lucb -> lu_session_limit) {
  175.                 p_lucb -> cur_sess++;
  176.              }
  177.              else
  178.                     {
  179.                         if (freesess(p_lucb) == -1) {
  180.                             p_sessa -> rc = UNSUC_RETRY;
  181.                             p_sessa -> p_scb = NULL;
  182.                 return 0;
  183.                         }
  184.                         else
  185.                                 {
  186.                                     p_lucb -> cur_sess++;
  187.                                 }
  188.                     }
  189.              /* Allocate new SCB */
  190.              if ((p_scb = malloc(sizeof(struct scb))) == NULL) {
  191.                   p_sessa -> rc = UNSUC_RETRY;
  192.                   p_sessa -> p_scb = NULL;
  193.           return 0;
  194.              }
  195.              /*
  196.               * Allocate RPL
  197.               */
  198.              if ((p_rpl = malloc(sizeof(struct rpl))) == NULL) {
  199.                   p_sessa -> rc = UNSUC_RETRY;
  200.                   p_sessa -> p_scb = NULL;
  201.           return 0;
  202.              }
  203.              i = 0;
  204.              memset(p_rpl, i, sizeof(struct rpl));
  205.              /*
  206.               * Allocate NIB
  207.               */
  208.              if ((p_nib = malloc(sizeof(struct nib))) == NULL) {
  209.                   p_sessa -> rc = UNSUC_RETRY;
  210.                   p_sessa -> p_scb = NULL;
  211.           return 0;
  212.              }
  213.              i = 0;
  214.              memset(p_nib, i, sizeof(struct nib));
  215.              p_scb -> p_rpl = p_rpl;
  216.              p_scb -> p_rcb = p_rcb;
  217.              p_rcb -> p_scb = p_scb;
  218.              p_scb -> use = IN_USE;
  219.              p_scb -> random_data = NULL;
  220.              p_scb -> next = NULL;
  221.              for (i = 0; i < 8; i++) {
  222.                 p_nib -> sym[i] = p_rcb -> lu_name[i];
  223.                 p_nib -> mode[i] = p_lucb -> lu_name[i];
  224.                 p_scb -> lu_name[i] = p_rcb -> lu_name[i];
  225.                 p_scb -> mode_name[i] = p_rcb -> mode_name[i];
  226.              }
  227.              if (temp1 == NULL) {
  228.                 p_lucb -> scb_list = p_scb;
  229.                 p_scb -> prev = NULL;
  230.              }
  231.              else
  232.                     {
  233.                         temp1 -> next = p_scb;
  234.                         p_scb -> prev = temp1;
  235.                     }
  236.              /*
  237.               * Set fields in RPL, NIB and issue OPNDST
  238.               */
  239.              p_rpl -> arg = p_nib;
  240.              p_rpl -> p_nib = p_nib;
  241.              p_rpl -> acb = p_lucb -> p_acb;
  242.              p_rpl -> rsrv3 = 0; /* primary LU */
  243.            /* Set correlator in RCB and NIB.user */
  244.              pr = p_rpl;
  245.              crl = pr;
  246.              p = &crl;
  247.              p_rcb -> sess_corl = crl;
  248.              for (i = 0; i < 4; i++) {
  249.                 p_nib -> user[i] = p[i];
  250.              }
  251.              p_sessa -> p_scb = p_scb;
  252.              p_rep = p_rcb -> verb_ptr;
  253.              p_rep -> p_rcb = p_rcb;
  254.  
  255. #if OS_TYPE == 1
  256. /*********  Trace facility **********/
  257. rtype = GREC;
  258. strcpy(pname, "getsess");
  259. pnum = 2;
  260. drec = p_nib;
  261. lenr = sizeof(struct nib);
  262. gtf(rtype, pname, pnum, drec, lenr);
  263. /***********************************/
  264. #endif
  265.  
  266.              if (opndst(p_rpl) != OK) {
  267.                 p_sessa -> rc = UNSUC_NO_RETRY;
  268.              }
  269.              else
  270.                     {
  271.                        p_sessa -> rc = OK;
  272.                        p_rep -> complete = 1; /* req. to retry */
  273.                     }
  274.              free(p_nib);
  275.              p_rpl -> p_nib = NULL;
  276.              return (0);
  277. }
  278. /*
  279.  * "Freesess" function closes unused sessions and removs the
  280.  * corresponded SCB from the SCB chain.
  281.  */
  282. freesess(p_lucb)
  283. struct lucb *p_lucb;
  284. {
  285.     struct scb *p_scb;
  286.     struct scb *temp;
  287.     struct scb *temp1;
  288.     struct rpl *p_rpl;
  289.     struct nib *p_nib;
  290.     unsigned cnt;
  291.  
  292. #if OS_TYPE == 1
  293. /*********  Trace facility **********/
  294. unsigned int rtype;   /* type of record */
  295. unsigned int pnum;    /* point number */
  296. char pname[8];        /* name of module */
  297. char *drec;           /* record for dump */
  298. int  lenr;            /* record length */
  299.  
  300. rtype = INPROC;
  301. strcpy(pname, "freeses");
  302. pnum = 1;
  303. drec = p_lucb;
  304. lenr = sizeof(struct lucb);
  305. gtf(rtype, pname, pnum, drec, lenr);
  306. /***********************************/
  307. #endif
  308.  
  309.     cnt = p_lucb -> cur_sess;
  310.     p_scb = p_lucb -> scb_list;
  311.  
  312.     while (p_scb != NULL) {
  313.        if (p_scb -> use == FREE) {
  314.           p_rpl = p_scb -> p_rpl;
  315.           clsdst(p_rpl);
  316.         /* remove SCB from chain */
  317.           temp = p_scb -> prev;
  318.           temp1 = p_scb -> next;
  319.           if (temp == NULL) {
  320.                 p_lucb -> scb_list = temp1;
  321.           }
  322.           else
  323.                 temp -> next = temp1;
  324.           if (temp1 != NULL)
  325.                 temp1 -> prev = temp;
  326.           p_nib = p_rpl -> p_nib;
  327.           free(p_rpl);
  328.           if (p_nib != NULL) {
  329.              free(p_nib);
  330.           }
  331.           free(p_scb);
  332.           p_lucb -> cur_sess--;
  333.        }
  334.        p_scb = p_scb -> next;
  335.     }
  336.     if (cnt == p_lucb -> cur_sess) {
  337.         return(-1); /* No SCB freed */
  338.     }
  339.     return(0);
  340. }
  341.